home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / GZIP107S.ZIP;1 / GZIP107.TAR / gzip-1.0.7 / znew.in < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.9 KB  |  127 lines

  1. :
  2. #!/bin/sh
  3.  
  4. check=0
  5. pipe=0
  6. opt=
  7. files=
  8. keep=0
  9. res=0
  10. old=0
  11. new=0
  12. block=1024
  13. # block is the disk block size (best guess, need not be exact)
  14.  
  15. warn="(does not preserve modes and timestamp)"
  16. echo hi > zfoo1$$
  17. echo hi > zfoo2$$
  18. if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then
  19.   cpmod=${CPMOD-cpmod}
  20.   warn=""
  21. fi
  22.  
  23. if test -z "$cpmod" && ${TOUCH-touch} -r zfoo1$$ zfoo2$$ 2>/dev/null; then
  24.   cpmod="${TOUCH-touch}"
  25.   cpmodarg="-r"
  26.   warn="(does not preserve file modes)"
  27. fi
  28. rm -f zfoo[12]$$
  29.  
  30. for arg
  31. do
  32.   case "$arg" in
  33.   -*)     opt="$opt $arg";;
  34.    *)     files="$files $arg";;
  35.   esac
  36. done
  37.  
  38. if test -z "$files"; then
  39.   echo 'recompress .Z files into .z (gzip) files'
  40.   echo usage: `echo $0 | sed 's,^.*/,,'` "[-tv9P]" file.Z...
  41.   echo "  -t tests the new files before deleting originals"
  42.   echo "  -v be verbose"
  43.   echo "  -9 use the slowest compression method (optimal compression)"
  44.   echo "  -K keep a .Z file when it is smaller than the .z file"
  45.   echo "  -P use pipes for the conversion $warn"
  46.   exit 1
  47. fi
  48. opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
  49. case "$opt" in
  50.   *t*) check=1; opt=`echo "$opt" | sed 's/t//g'`
  51. esac
  52. case "$opt" in
  53.   *K*) keep=1; opt=`echo "$opt" | sed 's/K//g'`
  54. esac
  55. case "$opt" in
  56.   *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'`
  57. esac
  58. if test -n "$opt"; then
  59.   opt="-$opt"
  60. fi
  61.  
  62. for i in $files; do
  63.   n=`echo $i | sed 's/.Z$//'`
  64.   if test ! -f $n.Z ; then
  65.     echo $n.Z not found
  66.     res=1; continue
  67.   fi
  68.   test $keep -eq 1 && old=`wc -c < $n.Z`
  69.   if test $pipe -eq 1; then
  70.     if gzip -d < $n.Z | gzip $opt > $n.z; then
  71.       # Copy file attributes from old file to new one, if possible.
  72.       test -n "$cpmod" && $cpmod $cpmodarg $n.Z $n.z 2> /dev/null
  73.     else
  74.       echo error while recompressing $n.Z
  75.       res=1; continue
  76.     fi
  77.   else
  78.     if test $check -eq 1; then
  79.       if cp -p $n.Z $n.$$ 2> /dev/null || cp $n.Z $n.$$; then
  80.     :
  81.       else
  82.     echo cannot backup $n.Z
  83.         res=1; continue
  84.       fi
  85.     fi
  86.     if gzip -d $n.Z; then
  87.       :
  88.     else
  89.       test $check -eq 1 && mv $n.$$ $n.Z
  90.       echo error while uncompressing $n.Z
  91.       res=1; continue
  92.     fi
  93.     if gzip $opt $n; then
  94.       :
  95.     else
  96.       test $check -eq 1 && mv $n.$$ $n.Z
  97.       echo error while recompressing $n
  98.       res=1; continue
  99.     fi
  100.   fi
  101.   test $keep -eq 1 && new=`wc -c < $n.z`
  102.   if test $keep -eq 1 -a `expr \( $old + $block - 1 \) / $block` -lt \
  103.                          `expr \( $new + $block - 1 \) / $block`; then
  104.     if test $pipe -eq 1; then
  105.       rm -f $n.z
  106.     elif test $check -eq 1; then
  107.       mv $n.$$ $n.Z && rm -f $n.z
  108.     else
  109.       gzip -d $n.z && compress $n && rm -f $n.z
  110.     fi
  111.     echo "$n.Z smaller than $n.z -- unchanged"
  112.  
  113.   elif test $check -eq 1; then
  114.     if gzip -t $n.z ; then
  115.       rm -f $n.$$ $n.Z
  116.     else
  117.       test $pipe -eq 0 && mv $n.$$ $n.Z
  118.       rm -f $n.z
  119.       echo error while testing $n.z, $n.Z unchanged
  120.       res=1; continue
  121.     fi
  122.   elif test $pipe -eq 1; then
  123.     rm -f $n.Z
  124.   fi
  125. done
  126. exit $res
  127.